package cn.maizi.shardingdemo.controller;


import cn.hutool.core.util.IdUtil;
import cn.maizi.shardingdemo.domain.OrderInfo;
import cn.maizi.shardingdemo.mapper.OrderMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@RestController
public class OrderController {
    @Autowired
    OrderMapper orderInfoMapper;

    //添加订单信息入库
    @GetMapping("/saveOrder")
    public String saveFk() {
        for (int i = 0; i < 10; i++) {
            //手动插入id
//            orderInfoMapper.insertOrder(i, i,"空调" + i, 1);
            //自动交给sharding-jdbc管理id
            orderInfoMapper.insertOrderBySNOWFLAKE( i,"空调" + i, 1);
        }
        return "success";
    }

    //查询订单信息
    @GetMapping("/queryOrders")
    public List<OrderInfo> queryOrders() {
        List<Long> ids = new ArrayList<>();
        ids.add(813420387835576320L);
        ids.add(813420387810410496L);
        return  orderInfoMapper.findOrderByIds(ids);
//        return orderList;
    }
}
